package com.mckillion.Exercise10;

class Mediator {
	private BtnEdit btnEdit;
 // 1. Add the other local versions of all the things that need to be mediated
 //    add all five of them here
	private BtnSearch btnSearch;
	private BtnBrowse btnBrowse;
	private LblDisplay lblDisplay;
	private ChkLock chkLock;
	
//---------------------------------------------------------------------------------------------------------------------
   // 2. register methods to set references to each concrete object to be mediated i.e. instantiate all of above
    public void registerEditButton(BtnEdit edt) {
        btnEdit = edt;
    }
 
    public void registerSearchButton(BtnSearch ser) {
    	btnSearch = ser;
	}
    
    public void registerBrowseButton(BtnBrowse bro) {
    	btnBrowse = bro;
	}
    
    public void registerLblDisplay(LblDisplay lbl) {
    	lblDisplay = lbl;
	}
    
    public void registerChkLock(ChkLock chk) {
    	chkLock = chk;
	}
    
    //---------------------------------------------------------------------------------------------------------------------
 //3. actions to take i.e. the mediation bit
    public void browseClicked() {
        btnBrowse.setEnabled(false);
        btnSearch.setEnabled(true);
        lblDisplay.setText("You are now browsing.");
        /*if (chkLock.isSelected())
        	btnEdit.setEnabled(true);*/
    }
    
    public void editClicked() {
    	btnEdit.setEnabled(false);
        lblDisplay.setText("You are now editing.");
        chkLock.setSelected(true);
        btnBrowse.setEnabled(true);
        btnSearch.setEnabled(true);
        /*if (chkLock.isSelected())
        	btnEdit.setEnabled(true);*/
    	}
    
    public void searchClicked() {
        btnBrowse.setEnabled(true);
        btnSearch.setEnabled(false);
        lblDisplay.setText("You are now searching.");
        /*if (chkLock.isSelected())
        	btnEdit.setEnabled(false);*/
    }

	public void registerFeedbackLabel(LblDisplay lbl) {
		lblDisplay = lbl;
		
	}

	public void lockSelected() {
		btnEdit.setEnabled(false);
	}

	public void unlockUnselected() {
		btnEdit.setEnabled(true);
	}
}
